package com.easyjava.qingke.memo.command.impl;

import com.easyjava.qingke.memo.command.SystemCommand;
import com.easyjava.qingke.memo.mybatis.pojo.Label;
import com.easyjava.qingke.memo.mybatis.pojo.MemoContent;
import com.easyjava.qingke.memo.mybatis.pojo.MemoLabel;
import com.easyjava.qingke.memo.util.MemoConsole;

public class AddCommand extends SystemCommand {

	public void excute() {

		MemoConsole.println("1.添加备忘录内容");
		MemoConsole.println("2.添加自定义标签");
		MemoConsole.println("3.给备忘录添加自定义标签");
		MemoConsole.println("=================");

		int id = MemoConsole.promptInt("请输入想要执行的操作的数字:");
		while (id > 0) {
			if (1==id) {
				addMemoContent();
				break;
			} else if (2==id) {
				addLabel();
				break;
			} else if (3==id) {
				addMemoContentToLabel();
				break;
			} else
				MemoConsole.println("输入的数字不存在！");
			id = MemoConsole.promptInt("请重新输入想要执行的操作的数字:");
		}
	}

	private void addMemoContentToLabel() {
		dao.selectMemoContent();
		
		MemoConsole.println();
		
		dao.selectLabel();
		
		MemoConsole.println();
		
		MemoLabel memoLabel =new MemoLabel();
		int memoContentId =MemoConsole.promptInt("请输入想要添加标签的备忘录ID：");
		while(!dao.isMemoContentIdExists(memoContentId)){
			MemoConsole.println("该ID不存在！");
			memoContentId=MemoConsole.promptInt("请重新输入想要添加标签的备忘录ID：");
		}
		int labelId=MemoConsole.promptInt("请输入标签ID：");
		while(!dao.isLabelIdExists(labelId)){
			MemoConsole.println("该ID不存在！");
			labelId=MemoConsole.promptInt("请重新输入标签ID：");
		}
		memoLabel.setMemoContentId(memoContentId);
		memoLabel.setLabelId(labelId);
		
		dao.addMemoLabel(memoLabel);
		
		
		
		
	}
	private void addLabel() {
		
		Label label=new Label();
		String name =MemoConsole.prompt("请输入标签的名称：");
		
		label.setName(name);
		dao.addLabel(label);
		
	}
	private void addMemoContent() {
		MemoContent memoContent =new MemoContent();
		
		String title=MemoConsole.prompt("请输入标题：");
		String content=MemoConsole.prompt("请输入内容：");
		
		memoContent.setTitle(title);
		memoContent.setContent(content);
		
		dao.addMemoContent(memoContent);
	}

}
